package com.jinkaimen.kqb.ui.activity;

import android.view.View;
import android.widget.Toast;

import com.ht.baselibs.ui.base.BaseActivity;
import com.jinkaimen.kqb.R;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;

/**
 * Created by lixuebo on 17/7/28.
 */

public class ShareActivity extends BaseActivity {
    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected void initTitleBar() {

        mTitleBarView.setTitleText("分享");
    }

    @Override
    protected int initContentView() {
        return R.layout.activity_share;
    }

    @Override
    protected void initChildView() {
        findViewById(R.id.bt_share).setOnClickListener(this);
    }

    @Override
    protected void initChildData() {

    }

    @Override
    protected void setChildViewListener() {

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);

        switch (v.getId()) {
            case R.id.bt_share:

                UMImage image = new UMImage(ShareActivity.this, "http://7xk9dj.com1.z0.glb.clouddn.com/refreshlayout/images/staggered11.png");//网络图片
//                UMImage image = new UMImage(ShareActivity.this, file);//本地文件
//                UMImage image = new UMImage(ShareActivity.this, R.drawable.xxx);//资源文件
//                UMImage image = new UMImage(ShareActivity.this, bitmap);//bitmap文件
//                UMImage image = new UMImage(ShareActivity.this, byte[]);//字节流
                UMImage thumb = new UMImage(this, R.mipmap.ic_launcher);
                image.setThumb(thumb);


                UMWeb web = new UMWeb("https://www.baidu.com");
                web.setTitle("This is music title");//标题
                web.setThumb(thumb);  //缩略图
                web.setDescription("my description");//描述


                new ShareAction(ShareActivity.this)
                        .withText("hello").withMedia(web)
                        .setDisplayList(SHARE_MEDIA.QQ, SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE)
                        .setCallback(shareListener)
                        .open();
                break;
        }

    }


    private UMShareListener shareListener = new UMShareListener() {
        /**
         * @descrption 分享开始的回调
         * @param platform 平台类型
         */
        @Override
        public void onStart(SHARE_MEDIA platform) {

        }

        /**
         * @descrption 分享成功的回调
         * @param platform 平台类型
         */
        @Override
        public void onResult(SHARE_MEDIA platform) {
            Toast.makeText(ShareActivity.this, "成功了", Toast.LENGTH_LONG).show();
        }

        /**
         * @descrption 分享失败的回调
         * @param platform 平台类型
         * @param t 错误原因
         */
        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            Toast.makeText(ShareActivity.this, "失败" + t.getMessage(), Toast.LENGTH_LONG).show();
        }

        /**
         * @descrption 分享取消的回调
         * @param platform 平台类型
         */
        @Override
        public void onCancel(SHARE_MEDIA platform) {
            Toast.makeText(ShareActivity.this, "取消了", Toast.LENGTH_LONG).show();

        }
    };
}
